<?php


namespace app\controller\Web;

use app\service\Web\MessageService;
use app\util\ResponseTrait;
use support\Db;
use support\Request;

use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("客户留言")
 */
class MessageController
{
    use ResponseTrait;

    /**
     * @Apidoc\Url("/web/message/add")
     * @Apidoc\Title("新增")
     * @Apidoc\Method("POST")
     * @Apidoc\Param("company_name",type="string",require=true,default="",desc="公司名称")
     * @Apidoc\Param("website",type="string",require=false,default="",desc="网址")
     * @Apidoc\Param("city",type="string",require=true,default="",desc="所属城市")
     * @Apidoc\Param("real_name",type="string",require=true,default="",desc="姓名")
     * @Apidoc\Param("mobile",type="string",require=true,default="",desc="手机")
     * @Apidoc\Param("content",type="string",require=true,default="",desc="内容")
     * @Apidoc\Param("pics",type="string",require=false,default="",desc="图片（多张使用英文逗号分隔）")
     *
     *
     */
    public function add(Request $request)
    {
        Db::beginTransaction();
        try {
            $where = [];
            $where['type'] = parameterCheck($request->input('type'), 'int', 0);
            $where['status'] = parameterCheck($request->input('status'), 'int', 10);
            $where['company_name'] = parameterCheck($request->input('company_name'), 'string', '');
            $where['website'] = parameterCheck($request->input('website'), 'string', '');
            $where['city'] = parameterCheck($request->input('city'), 'string', '');
            $where['real_name'] = parameterCheck($request->input('real_name'), 'string', '');
            $where['mobile'] = parameterCheck($request->input('mobile'), 'string', '');
            $where['content'] = parameterCheck($request->input('content'), 'string', '');
            $where['pics'] = parameterCheck($request->input('pics'), 'string', '');
            $data = MessageService::add($where);

            Db::commit();
            return $this->success($data);
        } catch (Throwable $e) {
            Db::rollBack();
            return $this->fail($e);
        }
    }

}